import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import java.util.Vector;

import Framework.*;



public class win_MediaLibrary extends pnl_Ancestor implements ActionListener{

	btn_TopButtons 		b_TopButtons 	= new btn_TopButtons("Media Library");
	btn_BottomButtons 	b_BottomButtons = new btn_BottomButtons(6);
	
	// Setting up scrollable, first Rectangle is the actual window dimensions, the second is the 'virtual' dimensions. I don't set
	// Virtual here, because I do it in win_Playlist instantiation.
	int			   	pnl_PlaylistWidth 		= 300;
	pnl_Scrollable 	pnl_Artist				= new pnl_Scrollable(new Rectangle(0,0,pnl_PlaylistWidth,600), new Rectangle(0,0,0,0), false);
	pnl_Scrollable 	pnl_Albums				= new pnl_Scrollable(new Rectangle(0,0,pnl_PlaylistWidth,600), new Rectangle(0,0,0,0), false);
	pnl_Scrollable 	pnl_Tracks				= new pnl_Scrollable(new Rectangle(0,0,pnl_PlaylistWidth,600), new Rectangle(0,0,0,0), false);
		
	btn_Ancestor btn_btm_PlayCD 			= new btn_Ancestor("Play CD");
	btn_Ancestor btn_btm_Artist 	= new btn_Ancestor("Artist");
	btn_Ancestor btn_btm_Album 	= new btn_Ancestor("Album");
	btn_Ancestor btn_btm_Track 			= new btn_Ancestor("Track");
	btn_Ancestor btn_btm_Sources 			= new btn_Ancestor("Edit Sources");

	JLabel lbl_Track 	= new JLabel("Stub");
	JLabel lbl_Artist 	= new JLabel("Stub");
	JLabel lbl_Album 	= new JLabel("Stub");
	
	dlg_Keyboard	dlg_SavePlaylist = new dlg_Keyboard("Save As: ", false);
	dlg_Keyboard	dlg_LoadPlaylist = new dlg_Keyboard("Open: ", false);

	
	public win_MediaLibrary(){
		super(); // Remember to always call super on JPanel_Anc constructors!
		
		// Setting up labels positions and adding to panel
		lbl_Track.setBounds(pnl_PlaylistWidth + 50, 150, pnl_PlaylistWidth, 50);
		lbl_Artist.setBounds(pnl_PlaylistWidth + 50, 260, pnl_PlaylistWidth, 50);
		lbl_Album.setBounds(pnl_PlaylistWidth + 50, 320, pnl_PlaylistWidth, 50);
		this.add(lbl_Track);
		this.add(lbl_Artist);
		this.add(lbl_Album);
			
		int li_yCoord 		= 0;
		int li_Spacer 		= 10; // Pixels between each button
		int li_buttonHeight = 60;
		btn_Ancestor lbtn_TempButton;
		
		for (int i = 0; i < is_Artists.length; i++){
			// Creating the button, setting size
			lbtn_TempButton = new btn_Ancestor(is_Artists[i]);
			lbtn_TempButton.setBounds(10, li_yCoord, pnl_PlaylistWidth, li_buttonHeight);
			
			// Adding event listener. As we don't really care which button is pressed, we just check
			// event to make sure that the parent frame is not this frame. Otherwise, We'd need to 
			// keep a reference to this button, and use e.getSource().equals(buttonReference);
			lbtn_TempButton.addActionListener(this);
			
			// Adding it to the playlist panel
			pnl_Artist.add(lbtn_TempButton);
			
			// Incrementing position.
			li_yCoord = li_yCoord + li_buttonHeight + li_Spacer;
		}
		pnl_Artist.setInternalFrameSize(new Rectangle(0,0,pnl_PlaylistWidth, li_yCoord));
		
		li_yCoord = 0;
		for (int i = 0; i < is_Albums.length; i++){
			lbtn_TempButton = new btn_Ancestor(is_Albums[i]);
			lbtn_TempButton.setBounds(10, li_yCoord, pnl_PlaylistWidth, li_buttonHeight);
			lbtn_TempButton.addActionListener(this);

			pnl_Albums.add(lbtn_TempButton);
			
			li_yCoord = li_yCoord + li_buttonHeight + li_Spacer;
		}
		pnl_Albums.setInternalFrameSize(new Rectangle(0,0,pnl_PlaylistWidth, li_yCoord));
		
		li_yCoord = 0;
		for (int i = 0; i < is_Tracks.length; i++){
			lbtn_TempButton = new btn_Ancestor(is_Tracks[i]);
			lbtn_TempButton.setBounds(10, li_yCoord, pnl_PlaylistWidth, li_buttonHeight);
			lbtn_TempButton.addActionListener(this);

			pnl_Tracks.add(lbtn_TempButton);
			
			li_yCoord = li_yCoord + li_buttonHeight + li_Spacer;
		}		
		pnl_Tracks.setInternalFrameSize(new Rectangle(0,0,pnl_PlaylistWidth, li_yCoord));
		
		this.add(pnl_Artist);
		this.add(pnl_Tracks);
		this.add(pnl_Albums);
		pnl_Tracks.setVisible(false);
		pnl_Albums.setVisible(false);
		
		// Adding top and bottom buttons. This should go last!
		// Adding bottom buttons to bottom Button frame
		b_BottomButtons.add(btn_btm_PlayCD, 0);
		b_BottomButtons.add(btn_btm_Artist, 1);
		b_BottomButtons.add(btn_btm_Album, 3);
		b_BottomButtons.add(btn_btm_Track, 4);
		b_BottomButtons.add(btn_btm_Sources, 5);
		
		// Adding listeners to bottom buttons. 
		btn_btm_Artist.addActionListener(this);
		btn_btm_Album.addActionListener(this);
		btn_btm_Track.addActionListener(this);
		
		// Adding top and bottom frames to this frame
		this.add(b_TopButtons);
		this.add(b_BottomButtons);
		
		// Call validate on completion of window. Otherwise some things may not render.
		this.validate();
		this.repaint();
		
		// Adding some filler into the open dialogue
		dlg_LoadPlaylist.addSuggestions();
		
	}	
	
	
	
	public void actionPerformed(ActionEvent e) {
		
		Object actionSource = (btn_Ancestor) e.getSource();
		
		if ( actionSource.equals(pnl_Artist) ){
			pnl_Artist.setVisible(false);
			pnl_Albums.setVisible(true);
			System.out.println("Got it!");
		} else if ( actionSource.equals(pnl_Albums)){
			pnl_Albums.setVisible(false);
			pnl_Tracks.setVisible(true);
			System.out.println("Got it!");
		} else if ( actionSource.equals(pnl_Tracks)){
			// changeMediaInfo();
		} else if (actionSource.equals(btn_btm_Artist) ){
			pnl_Artist.setVisible(true);
			pnl_Albums.setVisible(false);
			pnl_Tracks.setVisible(false);
			
		} else if (actionSource.equals(btn_btm_Album)) {
			pnl_Artist.setVisible(false);
			pnl_Albums.setVisible(true);
			pnl_Tracks.setVisible(false);
		} else if (actionSource.equals(btn_btm_Track)) {
			pnl_Artist.setVisible(false);
			pnl_Albums.setVisible(false);
			pnl_Tracks.setVisible(true);
		} //else if (actionSource.equals(btn_btm_Library)) {
			
		//	enterSubMenu(TeamRocket.w_MediaLibrary);			
		//}
		
	}
	
	
	// Stop reading here. The rest is just generation for track / album names etc.
	
	
	private Vector<String> createPlaylist(){
		// Creating a list of tracks titles / artists / albums
		Vector <String> ls_TrackList = new Vector<String>();
		String ls_Artist;
		String ls_Track;
		for (int i = 0; i < 50; i++){
			if (i < 10){
				ls_Artist = "Armin Van Buuren";
			} else if (i < 20){
				ls_Artist = "Tiesto";
			} else {
				ls_Artist = "Paul Oakenfold";
			}
			if (i % 3 == 0){
				ls_Track = "Get up and Dance!";
			} else if (i % 4 == 0){
				ls_Track = "Do something cool";
			} else if (i % 2 == 0){
				ls_Track = "Lets party";
			} else {
				ls_Track = "I have no friends.";
			}
			ls_TrackList.add(ls_Artist + " - " + ls_Track);
		}
		return ls_TrackList;
	}
	
	public void changeMediaInfo(){
		// Setting up media INformation for main pane.
		int i = new Random().nextInt(50);
		
		if (i < 10){ 
			lbl_Artist.setText("Armin Van Buuren"); 
		}
		else if (i < 20){ 
			lbl_Artist.setText("Tiesto"); 
		}
		else {
			lbl_Artist.setText("Paul Oakenfold"); 
		}
		
		if (i % 3 == 0) {
			lbl_Album.setText("Self Titled"); 
		}
		else {
			lbl_Album.setText("Party Anthems"); 
		}		
		if (i % 3 == 0){ 
			lbl_Track.setText("Get up and Dance!"); 
		} 
		else if (i % 4 == 0){
			lbl_Track.setText("Do something cool");
		} 
		else if (i % 2 == 0){
			lbl_Track.setText("Lets party"); 
		} 
		else {
			lbl_Track.setText("I have no friends."); 
		}		
		this.validate();
		this.repaint();
	}
	
	// These are totally not my personal music collection, pulled via a bit of python butchering. 
	String[] is_Artists = new String[] {"Grinspoon","28 Days","The Bloodhound Gang","Jack Johnson","Coldplay","James Blunt",
									"REM","Imogen Heap","Grey Daze","Oasis","The Killers","Nirvana","Deftones","Green Day","Ben Lee",
									"Limp Bizkit","Cold Play","3 Doors Down","Fall Out Boy","Yellowcard","Red Hot Chili Peppers","Dido","P.O.D.",
									"Papa Roach","Blink 182","MGMT","Placebo","Linkin Park","Silverchair","Alien Ant Farm","Offspring","The Androids"};
	String[] is_Albums = new String[] {"Guide To Better Living","Thrills, Kills & Sunday Pills","Easy","28 Days","Upstyledown",
									"Stealing Chairs","Hooray for Boobies","En Concert CDRip 2009 ","Parachutes","X & Y",
									"A Rush Of Blood To The Head","All The Lost Souls ","Back To Bedlam",
									"Chasing Time The Bedlam Sessions Live (2006)","Reveal (2001)","Up (1999)",
									"In Time (2003)","Around the Sun (2004)","Speak for Yourself (2005)","Wake Me (1994)",
									"...No Sun Today (1997)","Heathen Chemistry","Day And Age ","Hot Fuss",
									"From the Muddy Banks of the Wishkah","Bleach","Unplugged In Newyork","Nevermind"};
	String[] is_Tracks = new String[] {"Boundary","Scalped","Freezer (Live)","Post Enebriated Anxiety (Live)","Railrider","Balding Matters","NBT","Just Ace (Live)",
									"Don't Go Away","Just Ace","Repeat","Dead Cat 3X","Sickfest","More Than You Are (Live)","NBT (Live)","Post Enebriated Anxiety","Pedestrian",
									"Pressure Tested","Champion","Bad Funk Stripe","Truk","Hideaway","Enemy","Rising Tide","Bleed You Dry","She's Leaving Tuesday","Kiss It",
									"Hard Act To Follow","Choke","Better Off Alone","Replacements","Hold On Me","Nylon","Grinspoon_-_07_-_Rock_Show","Grinspoon_-_09_-_Better_Off_Dead",
									"Grinspoon_-_11_-_All_The_Time","Grinspoon_-_10_-_Violent_And_Lazy","Grinspoon_-_08_-_Overdriver","Grinspoon_-_01_-_American_Party_Bomb",
									"Grinspoon_-_03_-_Undercover","Grinspoon_-_12_-_Yarni_Marni","Grinspoon_-_06_-_Ordinary","Grinspoon_-_02_-_Ready_1","Grinspoon_-_13_-_SignPost",
									"Grinspoon_-_14_-_Dial_Tone","Grinspoon_-_04_-_Tang","Grinspoon_-_05_-_Secrets","28 Days - 28 Days - 08 - He Could Be"};								
									
	
}
